package com.api.customization.huangwm.localStorage;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;

import weaver.conn.RecordSet;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.job.JobTitlesComInfo;

import com.engine.common.util.ParamUtil;

/**
 * @author Huangwm
 * @package com.api.customization.huangwm.localStorage
 * @description
 */
public class GetResourceInfoApi {

    private Log log = new LogFactory().getLog("custom_huangwm");

    /**
     * 根据用户id获取信息,不传id则获取当前用户
     *
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getUserInfo")
    @Produces(MediaType.APPLICATION_JSON)
    public static Map<String, Object> get(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        User user = null;
        String getuserid = "";
        try {
            HttpSession session = request.getSession();
            user = (User) session.getAttribute("weaver_user@bean");
            Map<String, Object> params = ParamUtil.request2Map(request);
            Map<String, Object> result = new HashMap<String, Object>();
            RecordSet rs = new RecordSet();
            DepartmentComInfo depInfo = new DepartmentComInfo();
            JobTitlesComInfo jobInfo = new JobTitlesComInfo();
            SubCompanyComInfo subInfo = new SubCompanyComInfo();
            if (params.containsKey("userid"))
                getuserid = params.get("userid").toString();
            else
                getuserid = user.getUID() + "";
            String sql = "select * from HrmResource where id=" + getuserid;
            rs.writeLog("com.api.customization.localStorage->>>" + sql);
            if (rs.execute(sql) && rs.next()) {
                result.put("loginid", rs.getString("loginid"));
                result.put("lastname", rs.getString("lastname"));
                result.put("sex", rs.getString("sex"));
                result.put("birthday", rs.getString("birthday"));
                result.put("mobile", rs.getString("mobile"));
                result.put("email", rs.getString("email"));
                result.put("jobtitle", rs.getString("jobtitle"));
                result.put("jobtitlename", jobInfo.getJobTitlesmark(rs.getString("jobtitle")));
                result.put("joblevel", rs.getString("joblevel"));
                result.put("seclevel", rs.getString("seclevel"));
                result.put("departmentid", rs.getString("departmentid"));
                result.put("departmentname", depInfo.getDepartmentmark(rs.getString("departmentid")));
                result.put("subcompanyid1", rs.getString("subcompanyid1"));
                result.put("subconpanyidname", subInfo.getSubCompanyname(rs.getString("subcompanyid1")));
                result.put("managerid", rs.getString("managerid"));
                result.put("status", rs.getString("status"));
                result.put("messagerurl", rs.getString("messagerurl"));
            }
            apidatas.put("result", result);
            apidatas.put("apistatus", true);
            apidatas.put("getuserid", getuserid);
            apidatas.put("currentuser", user.getUID() + "");
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("result", e.getMessage());
            apidatas.put("apistatus", false);
            apidatas.put("getuserid", getuserid);
            apidatas.put("currentuser", user.getUID() + "");
        }
        return apidatas;
    }
}
